import { createRouter, createWebHashHistory } from 'vue-router';

const routes = [
  {
    path: '/article/:id',
    name: 'article',
    component: () => import('@/pages/article/index.vue'),
    meta: { title: '文章' },
  },
  {
    path: '/',
    name: 'home',
    component: () => import('@/pages/home/index.vue'),
    children: [],
    meta: { title: '首页' },
  },
  {
    path: '/personalCenter',
    name: 'personalCenter',
    component: () => import('@/pages/myCenter/index.vue'),
    children: [],
    meta: { title: '个人中心' },
  },
  {
    path: '/pictureWall',
    name: 'pictureWall',
    component: () => import('@/pages/pictureWall/index.vue'),
    meta: { title: '照片墙' },
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  linkActiveClass: 'active',
  routes,
});

router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    window.document.title = to.meta.title;
  }
  next();
});

export default router;
